#!/bin/zsh -Ndefgku
#
# Scripts/bootstrap
# mas
#
# Copyright © 2025 mas-cli. All rights reserved.
#
# Installs dependencies for Scripts/format & Scripts/lint.
#
# Usage: bootstrap [<brew-bundle-install-argument>...]
#

. "${0:A:h}/_setup_script"

print_notice '👢 Bootstrapping' "${@}"

if ! whence brew >/dev/null; then
	/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

brew update -q
installed_formulae=("${(f)$(brew list --formulae)}")
readonly -a installed_formulae
bootstrap_formulae=("${(f)$(brew deps --union "${(f)$(brew bundle list --formulae)}")}")
readonly -a bootstrap_formulae
# shellcheck disable=SC2086
(("${#installed_formulae:*bootstrap_formulae}")) && brew upgrade --overwrite -q ${installed_formulae:*bootstrap_formulae}
brew bundle upgrade -fq "${@}"
brew upgrade --overwrite -q "${bootstrap_formulae[@]}"
